package com.handersome.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.handersome.bean.User;
import com.handersome.exception.MyException;
import com.handersome.service.PropertiesService;

/**
 * rest 风格的web应用
 * @author handersome
 *
 * @version 创建时间：2017年11月30日 下午5:20:46
 */
@RestController
public class HelloController {
	
	@Autowired
	PropertiesService ppService;

	@RequestMapping("/hello")
	public String index(){
		return "hello world";
	}
	
	@RequestMapping("/user")
	public User user(){
		User u = new User();
		u.setAge(ppService.getAge());
		u.setDesc(ppService.getRandomString());
		u.setName(ppService.getName());
		u.setId(ppService.getId());
		u.setNumRange(ppService.getRandomRangeInt());
		u.setNumLen(ppService.getRandomLengthInt());
		return u;
	}
	
	/**
	 * 测试统一异常处理
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/errortest")
	public String errorTest() throws Exception{
		throw new Exception();
	}
	
	/**
	 * 测试统一异常处理
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/myerrortest")
	public String myErrorTest() throws MyException{
		throw new MyException();
	}
}
